package com.ubs.training.web.util;

import com.ubs.training.server.dao.model.LinkClient;
import org.springframework.util.StringUtils;
import org.springframework.validation.Errors;

/**
 * Created with IntelliJ IDEA.
 * User: xubuntu
 * Date: 8/23/12
 * Time: 3:21 AM
 * To change this template use File | Settings | File Templates.
 */
public class LinkClientValidator {
    private LinkClient linkclient;
    private Errors res;

    public LinkClientValidator(LinkClient linkclient, Errors res) {
        this.linkclient = linkclient;
        this.res = res;

    }



    public void validate() {
        if(!StringUtils.hasLength(linkclient.getContact_person_name())) {
            res.rejectValue("contact_person_name", "empty");
        }
        if(linkclient.getStatus()<0||linkclient.getStatus()>1){
            res.rejectValue("status", "active", "Status value can be 0-inactive or 1 - active");
        }
        if(linkclient.getTarget_client_id()==0){
            res.rejectValue("target_client_id", "zero", "Id can't be with value 0");
        }
        if(linkclient.getLink_type_id()==0){
            res.rejectValue("link_type_id", "zero", "Id can't be with value 0");
        }



    }


}





